package com.jxd.project.report.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jxd.project.report.dao.IProjectDao;
import com.jxd.project.report.model.Project;
import com.jxd.project.report.service.IProjectService;
import com.jxd.project.report.vo.ProjectWithDname;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @ClassName ProjectServiceImpl
 * @Description TODO
 * @Author 孙福桐
 * @Date 2025/10/1 18:25
 * @Version 1.0
 */
@Service
public class ProjectServiceImpl extends ServiceImpl<IProjectDao, Project> implements IProjectService {
    @Autowired
    private IProjectDao projectDao;

    @Override
    public boolean addProject(Project project) {
        return projectDao.insertProject(project);
    }

    @Override
    public Map<String, Object> getProject(Map<String, String> paramMap) {
        Map<String, Object> result = new HashMap<>();

        String pname = paramMap.get("pname");
        String deptno =paramMap.get("deptno");
        String page = paramMap.get("page");
        String limit = paramMap.get("limit");
        if (page != null && limit != null) {
            IPage<ProjectWithDname> projectWithDnamePage = new Page<>(Integer.parseInt(page), Integer.parseInt(limit));
            projectWithDnamePage = projectDao.selectProjectWithDname(projectWithDnamePage, pname, deptno);
            result.put("data", projectWithDnamePage.getRecords());
            result.put("count", projectWithDnamePage.getTotal());
            result.put("code", 0);
            return result;
        } else {
            result.put("data", (Object)null);
            result.put("code", "500");
            result.put("msg", "参数不符");
            result.put("count", (Object)null);
            return result;
        }
    }

    @Override
    public boolean removeProject(List<Integer> pids) {
        UpdateWrapper<Project> updateWrapper = new UpdateWrapper<>();
        updateWrapper.in("pid", pids)
                .set("isdelete", 1);
        return projectDao.update(null,updateWrapper) > 0;
    }
}
